package com.gopay.scheduler.job;

import java.util.Date;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.gopay.common.util.DateUtils;
import com.gopay.scheduler.GopayBaseJob;
import com.gopay.scheduler.service.cacert.CustMobCaCertService;
import com.gopay.scheduler.service.cacert.impl.CustCaCertServiceImpl;

/**
 * @ClassName: AutoRecoveryCertJob 
 * @Description: 自动回收数字证书 
 * @author alibaba规范前
 * @date 2017年12月21日 上午9:54:04
 */
public class AutoRecoveryCertJob extends GopayBaseJob{

    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private CustCaCertServiceImpl custCaCertServiceCron;
    
    @Resource(name = "custMobCaCertService")
    private CustMobCaCertService custMobCaCertService;
    
    @Override
    protected void doJobInternal() {
        logger.info("开始执行数字证书回收任务...");
        Date date =new Date();
        
        String currentTs = DateUtils.date2string(date, "yyyy-MM-dd");
        
        try {
            custCaCertServiceCron.recoveryEquiredCert(currentTs);
            logger.info("数字证书回收任务执行成功.");
        } catch (Exception e) {
            logger.error("执行数字证书回收任务出现异常: " + e.getMessage());
        }
        
        try {
            custMobCaCertService.recoveryEnpiredCert();
            logger.info("移动数字证书回收任务执行成功.");
        } catch (Exception e) {
            logger.error("执行移动数字证书回收任务出现异常: " + e.getMessage());
        }
    }

}
